<?php
require dirname(__DIR__).'/unit_test_conf.php';
require __DIR__.'/Class.php';
define('NAME', basename(__DIR__));

/**
 *	
 */
class UnitTest extends PHPUnit_Framework_TestCase
{
	################################################################################################################################
	#	1. Setting Basic varialbes for Testing..
	################################################################################################################################
	protected static $error;
	protected static $banner_seq;
	
	################################################################################################################################
	#	2. Basic Method Testing..
	################################################################################################################################

	/**
	 * 
	 */
	public function testInsert4Class()
	{
		try
		{
			$o = Wdk::get(NAME);
			$o['banner_code']	= utRc(3);
			$o['banner_name']	= utRc(rand(10,40));
			$o['banner_type']	= utRand(BANNER_TYPE_SWF,BANNER_TYPE_IMG);
			$o['banner_file']	= array('size'=>rand(10,99), 'name'=>utRc(10), 'path'=>utRc(rand(15,20)));
			$o['banner_link']	= utRc(rand(20,30));
			$o['banner_width']	= rand(10,99);
			$o['banner_height']	= rand(10,99);
			$o['banner_target']	= utRand(BANNER_TARGET_SELF,BANNER_TARGET_BLANK);
			$o->insert();

			self::$banner_seq = $o['banner_seq'];
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$banner_seq);
			$this->assertEquals($o['banner_code']	, $c['banner_code']		, "[Error] banner_code");
			$this->assertEquals($o['banner_name']	, $c['banner_name']		, "[Error] banner_name");
			$this->assertEquals($o['banner_type']	, $c['banner_type']		, "[Error] banner_type");
			$this->assertEquals($o['banner_file']	, $c['banner_file']		, "[Error] banner_file");
			$this->assertEquals($o['banner_link']	, $c['banner_link']		, "[Error] banner_link");
			$this->assertEquals($o['banner_width']	, $c['banner_width']	, "[Error] banner_width");
			$this->assertEquals($o['banner_height']	, $c['banner_height']	, "[Error] banner_height");
			$this->assertEquals($o['banner_target']	, $c['banner_target']	, "[Error] banner_target");
			$this->assertEquals($o['banner_link']	, $c['banner_link']		, "[Error] banner_link");
			$this->assertEquals('T'					, $c['banner_use_flag']	, "[Error] banner_use_flag");
			$this->assertEquals('F'					, $c['banner_del_flag']	, "[Error] banner_del_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	
	/**
	 *	
	 */
	public function testUpdate4Class()
	{
		if(self::$error == true) return;
		try
		{
			$o = Wdk::get(NAME);
			$o->load(self::$banner_seq);
			$o['banner_name']		= utRc(rand(10,40));
			$o['banner_type']		= utRand(BANNER_TYPE_SWF,BANNER_TYPE_IMG);
			$o['banner_file']		= array('size'=>rand(10,99), 'name'=>utRc(10), 'path'=>utRc(rand(15,20)));
			$o['banner_link']		= utRc(rand(20,30));
			$o['banner_width']		= rand(10,99);
			$o['banner_height']		= rand(10,99);
			$o['banner_target']		= utRand(BANNER_TARGET_SELF,BANNER_TARGET_BLANK);
			$o['banner_use_flag']	= utRand('T','F');
			$o->update();
			
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$banner_seq);
			$this->assertEquals($o['banner_code']		, $c['banner_code']		, "[Error] banner_code");
			$this->assertEquals($o['banner_name']		, $c['banner_name']		, "[Error] banner_name");
			$this->assertEquals($o['banner_type']		, $c['banner_type']		, "[Error] banner_type");
			$this->assertEquals($o['banner_file']		, $c['banner_file']		, "[Error] banner_file");
			$this->assertEquals($o['banner_link']		, $c['banner_link']		, "[Error] banner_link");
			$this->assertEquals($o['banner_width']		, $c['banner_width']	, "[Error] banner_width");
			$this->assertEquals($o['banner_height']		, $c['banner_height']	, "[Error] banner_height");
			$this->assertEquals($o['banner_target']		, $c['banner_target']	, "[Error] banner_target");
			$this->assertEquals($o['banner_link']		, $c['banner_link']		, "[Error] banner_link");
			$this->assertEquals($c['banner_use_flag']	, $c['banner_use_flag']	, "[Error] banner_use_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	
	/**
	 *	
	 */
	public function testDelete4Class()
	{
		if(self::$error == true) return;
		try
		{
			$o = Wdk::get(NAME);
			$o->load(self::$banner_seq);
			$o->delete();
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$banner_seq);
			$this->assertEquals('T'	, $c['banner_del_flag']	, "[Error] banner_del_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	################################################################################################################################
	#	3. Manager Method Testing..
	################################################################################################################################
	/**
	 * 
	 */
	public function testLoad4Manager()
	{
		if(self::$error == true) return;
		try
		{
			$cm = Wdk::get(NAME.'Manager');
			$cm->load();
		}
		catch(NoRecordException $e){}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	################################################################################################################################
	#	4. Scenario Testing..
	#	-> a)
	################################################################################################################################
	
	################################################################################################################################
	#	5. Testing tool Methods
	################################################################################################################################
	private function removeTestData()
	{

	}
	public function setUp()
	{
		//	no need..
	}
	public function tearDown()
	{
		//	no need..
	}
	################################################################################################################################
}
?>